package org.red.checkSystem.controller.check;

import com.alibaba.fastjson2.JSON;
import org.red.checkSystem.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.red.checkSystem.service.check.checkCRUDService;

import java.util.Map;

@RestController
@RequestMapping("/check")
public class checkCRUDController {
    @Autowired
     private checkCRUDService checkCRUDService;

    @PostMapping("/addArticle/")
    public String addArticle(@RequestParam MultiValueMap<String,String> map){
        Article article = JSON.parseObject(map.getFirst("article"),Article.class);

        return checkCRUDService.addArticleUnCheck(article,map.getFirst("address"));
    }
    @PostMapping("/checkArticle/")
    public String checkArticle(@RequestParam MultiValueMap<String,String> map){
        int id = Integer.parseInt(map.getFirst("id"));
        String state = map.getFirst("state");
        String admin = map.getFirst("admin");
        return checkCRUDService.checkArticle(id,state,admin);
    }
    @PostMapping("/getAuthor/")
    public String getAuthor(@RequestParam MultiValueMap<String,String> map){
        return checkCRUDService.getAuthor(Integer.parseInt(map.getFirst("id")));
    }
    @PostMapping("/deteleArticle/")
    public String deteleArticle(@RequestParam MultiValueMap<String,String> map){
        return checkCRUDService.deteleArticle(Integer.parseInt(map.getFirst("id")));
    }
    @PostMapping("/updataArticle/")
    public String updataArticle(@RequestParam MultiValueMap<String,String> map){
        Article article = JSON.parseObject(map.getFirst("article"),Article.class);
        String address = map.getFirst("address");
        System.out.println(address);
        System.out.println();
        System.out.println("laksndasdas");
        return checkCRUDService.updataArticle(article,address);
    }
}
